<?php
namespace Model;
use Think\Model;

class SubscribeModel extends Model {
//    protected $patchValidate = true;    //开启批处理验证
	    protected $_validate = array(
		array('user_account', 'require', '手机号不能为空'),
		array('user_account', '', '该用户已预约',0,'unique'),
		array('name', 'require', '姓名不能为空'),
		array('authCode', 'require', '验证码不能为空'),
		array('weixin_openid', '', '该用户已预约',0,'unique'),
		array('weixin_openid', 'require', '请重新打开网页'),

    );
	
//    检验验证码
    public function checkAuthCode($user_account, $authCode) {
		//查询验证码是否存在
		$data = M('temp_user');
		$condition['temp_user_tel'] = $user_account;
		$condition['temp_user_authcode'] = $authCode;
		$info = $data->where($condition)->select();
	//	dump($info);
		//若无法匹配验证码，则返回false
		if(!$info) {
	//	    echo "验证码有误";
		    return false;
		}
	//	dump($info);
		//判断验证码是否在有效期内
		$authCodeTime = strtotime($info[0]['temp_user_authcode_time']);
		$currentTime = strtotime('now');
		$s = $currentTime - $authCodeTime;
		//验证码时间为2分钟（120）秒，超过则无效
		if($s > 120){
	//	    echo "验证码无效";
		    return false;
		}else
		    return true;
	}
	    
    //获取预约学校列表
    public function getSubscribeSchoolList() {
		$school = M('subscribe_school');
	//	$condition['subscribe_school'] = $user_account;
		$schoolList = $school -> where() ->select();
		return $schoolList;
	}
    
    
    
    
    
    

}